package com.cropdoctor.controller;

import com.cropdoctor.common.Result;
import com.cropdoctor.model.dto.FeedBackDto;
import com.cropdoctor.model.po.FeedBackPo;
import com.cropdoctor.service.FeedBackService;
import com.cropdoctor.util.ContextGet;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/feedback")
@Api(tags = "用户反馈模块")
public class FeedBackController {

    @Autowired
    FeedBackService feedBackService;

    //region反馈模块（用户端）
    @PostMapping()
    @ApiOperation("（用户端）用户提交一条新反馈")
    public Result<String> submitFeedBack(@RequestBody FeedBackPo feedBackPo){
        return feedBackService.submitFeedBack(feedBackPo);
    }

    @GetMapping()
    @ApiOperation("（用户端）通过传入的id查询用户所有的反馈记录")
    public Result<List<FeedBackDto>> getHistoryFeedBack(){
        long userId = ContextGet.getUserId();
        return feedBackService.getHistoryFeedBack(userId);
    }

    @PutMapping("")
    @ApiOperation("(用户端) 通过主键id让用户修改自己提交过的反馈")
    public Result<String> updateFeedBack(@RequestBody FeedBackPo feedBackPo){
        return feedBackService.updateFeedBack(feedBackPo);
    }

    @DeleteMapping("/user/id/{id}")
    @ApiOperation("(用户端) 通过传入主键id让用户删除自己提交过的反馈")
    public Result<String> deleteFeedBackById(@PathVariable("id") Long id){ return feedBackService.userDeleteById(id); }
    //endregion


}
